package com.dp.factory.schemes1.controller;

import com.dp.factory.schemes1.entity.AwardInfo;
import com.dp.factory.schemes1.entity.DiscountResult;
import com.dp.factory.schemes1.entity.SmallGiftInfo;
import com.dp.factory.schemes1.service.DiscountService;
import com.dp.factory.schemes1.service.SmallGiftService;
import com.dp.factory.schemes1.service.YoukuMemberService;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * 发放奖品接口
 */
public class DeliverController {

    /**
     * 按照奖品类型发放奖品
     *
     * @param awardInfo
     */
    public void awardToUser(AwardInfo awardInfo) {
        if (awardInfo.getAwardTypes() == 1) {
            //打折券
            DiscountService discountService = new DiscountService();
            DiscountResult discountResult = discountService.sendDiscount(awardInfo.getUid(), awardInfo.getAwardNumber());
            System.out.println("打折券发送成功" + discountResult);
        } else if (awardInfo.getAwardTypes() == 2) {
            //优酷会员
            String phone = awardInfo.getExtMap().get("phone");
            YoukuMemberService youkuMemberService = new YoukuMemberService();
            youkuMemberService.openMember(phone, awardInfo.getAwardNumber());
            System.out.println("优酷会员发放成功");
        } else if (awardInfo.getAwardTypes() == 3) {
            SmallGiftInfo smallGiftInfo = new SmallGiftInfo();
            smallGiftInfo.setUserPhone(awardInfo.getExtMap().get("phone"));
            smallGiftInfo.setUserName(awardInfo.getExtMap().get("username"));
            smallGiftInfo.setAddress(awardInfo.getExtMap().get("address"));
            smallGiftInfo.setOrderId(UUID.randomUUID().toString());
            //小礼品
            SmallGiftService smallGiftService = new SmallGiftService();
            Boolean b = smallGiftService.giveSmallGift(smallGiftInfo);
            if (b) {
                System.out.println("小礼品发送成功");
            }
        }
    }

}
